<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="keywords" content="Hexo Theme Keep">
    <meta name="description" content="Hexo Theme Keep">
    <meta name="author" content="aaton">
    
    <title>
        
            Javascript之数据类型 |
        
        aaton&#39;s study notes
    </title>
    
<link rel="stylesheet" href="/css/style.css">

    <link rel="shortcut icon" href="/images/logo.svg">
    
<link rel="stylesheet" href="/font/css/fontawesome.min.css">

    
<link rel="stylesheet" href="/font/css/regular.min.css">

    
<link rel="stylesheet" href="/font/css/solid.min.css">

    
<link rel="stylesheet" href="/font/css/brands.min.css">

    <script id="hexo-configurations">
    let KEEP = window.KEEP || {}
    KEEP.hexo_config = {"hostname":"example.com","root":"/","language":"en"}
    KEEP.theme_config = {"toc":{"enable":false,"number":false,"expand_all":false,"init_open":false},"style":{"primary_color":"#0066cc","logo":"/images/logo.svg","favicon":"/images/logo.svg","avatar":"/images/avatar.svg","font_size":null,"font_family":null,"hover":{"shadow":false,"scale":false},"first_screen":{"enable":true,"header_transparent":true,"background_img":"/images/bg.svg","description":"Keep writing and Keep loving.","font_color":null,"hitokoto":true},"scroll":{"progress_bar":false,"percent":false}},"local_search":{"enable":false,"preload":false},"code_copy":{},"code_block":{"tools":{"enable":true,"style":"default"},"highlight_theme":"default"},"side_tools":{},"pjax":{"enable":false},"lazyload":{"enable":false},"comment":{"enable":false,"use":"valine","valine":{"appid":null,"appkey":null,"server_urls":null,"placeholder":null},"gitalk":{"github_id":null,"github_admins":null,"repository":null,"client_id":null,"client_secret":null,"proxy":null},"twikoo":{"env_id":null,"region":null,"version":"1.6.8"},"waline":{"server_url":null,"reaction":false,"version":2}},"post":{"author_label":{"enable":true,"auto":true,"custom_label_list":["Trainee","Engineer","Architect"]},"word_count":{"enable":true,"wordcount":true,"min2read":true},"img_align":"left","copyright_info":false},"version":"3.6.1"}
    KEEP.language_ago = {"second":"%s seconds ago","minute":"%s minutes ago","hour":"%s hours ago","day":"%s days ago","week":"%s weeks ago","month":"%s months ago","year":"%s years ago"}
    KEEP.language_code_block = {"copy":"Copy code","copied":"Copied","fold":"Fold code block","folded":"Folded"}
    KEEP.language_copy_copyright = {"copy":"Copy copyright info","copied":"Copied","title":"Original article title","author":"Original article author","link":"Original article link"}
  </script>
<meta name="generator" content="Hexo 6.3.0"></head>


<body>
<div class="progress-bar-container">
    

    
</div>


<main class="page-container">

    

    <div class="page-main-content">

        <div class="page-main-content-top">
            
<header class="header-wrapper">

    <div class="header-content">
        <div class="left">
            
                <a class="logo-image" href="/">
                    <img src="/images/logo.svg">
                </a>
            
            <a class="logo-title" href="/">
               aaton&#39;s study notes
            </a>
        </div>

        <div class="right">
            <div class="pc">
                <ul class="menu-list">
                    
                        <li class="menu-item">
                            <a class=""
                               href="/"
                            >
                                HOME
                            </a>
                        </li>
                    
                        <li class="menu-item">
                            <a class=""
                               href="/archives"
                            >
                                ARCHIVES
                            </a>
                        </li>
                    
                        <li class="menu-item">
                            <a class=""
                               href="/tags"
                            >
                                TAGS
                            </a>
                        </li>
                    
                        <li class="menu-item">
                            <a class=""
                               href="/categories"
                            >
                                CATEGORIES
                            </a>
                        </li>
                    
                        <li class="menu-item">
                            <a class=""
                               href="/about"
                            >
                                ABOUT
                            </a>
                        </li>
                    
                    
                </ul>
            </div>
            <div class="mobile">
                
                <div class="icon-item menu-bar">
                    <div class="menu-bar-middle"></div>
                </div>
            </div>
        </div>
    </div>

    <div class="header-drawer">
        <ul class="drawer-menu-list">
            
                <li class="drawer-menu-item flex-center">
                    <a class=""
                       href="/">HOME</a>
                </li>
            
                <li class="drawer-menu-item flex-center">
                    <a class=""
                       href="/archives">ARCHIVES</a>
                </li>
            
                <li class="drawer-menu-item flex-center">
                    <a class=""
                       href="/tags">TAGS</a>
                </li>
            
                <li class="drawer-menu-item flex-center">
                    <a class=""
                       href="/categories">CATEGORIES</a>
                </li>
            
                <li class="drawer-menu-item flex-center">
                    <a class=""
                       href="/about">ABOUT</a>
                </li>
            
        </ul>
    </div>

    <div class="window-mask"></div>

</header>


        </div>

        <div class="page-main-content-middle">

            <div class="main-content">

                
                    <div class="fade-in-down-animation">
    <div class="post-page-container">
        <div class="article-content-container">

            <div class="article-title">
                <span class="title-hover-animation">Javascript之数据类型</span>
            </div>

            
                <div class="article-header">
                    <div class="avatar">
                        <img src="/images/avatar.svg">
                    </div>
                    <div class="info">
                        <div class="author">
                            <span class="name">aaton</span>
                            
                                <span class="author-label">Lv3</span>
                            
                        </div>
                        <div class="meta-info">
                            
<div class="article-meta-info">
    <span class="article-date article-meta-item">
        
            <i class="fa-regular fa-calendar-plus"></i>&nbsp;
        
        <span class="pc">2023-06-05 11:00:11</span>
        <span class="mobile">2023-06-05 11:00</span>
    </span>
    
        <span class="article-update-date article-meta-item">
        <i class="fas fa-file-pen"></i>&nbsp;
        <span class="pc">2023-05-11 23:34:12</span>
    </span>
    
    
        <span class="article-categories article-meta-item">
            <i class="fas fa-folder"></i>&nbsp;
            <ul>
                
                    <li>
                        <a href="/categories/Javascript/">Javascript</a>&nbsp;
                    </li>
                
            </ul>
        </span>
    
    
        <span class="article-tags article-meta-item">
            <i class="fas fa-tags"></i>&nbsp;
            <ul>
                
                    <li>
                        <a href="/tags/Javascript%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B/">Javascript数据类型</a>&nbsp;
                    </li>
                
            </ul>
        </span>
    

    
    
        <span class="article-wordcount article-meta-item">
            <i class="fas fa-file-word"></i>&nbsp;<span>1.9k Words</span>
        </span>
    
    
        <span class="article-min2read article-meta-item">
            <i class="fas fa-clock"></i>&nbsp;<span>8 Mins</span>
        </span>
    
    
        <span class="article-pv article-meta-item">
            <i class="fas fa-eye"></i>&nbsp;<span id="busuanzi_value_page_pv"></span>
        </span>
    
</div>

                        </div>
                    </div>
                </div>
            

            <div class="article-content keep-markdown-body">
                

                <p><img src="https://cn.bing.com/th?id=OHR.JavaBromo_ZH-CN2744043733_1920x1200.jpg&rf=LaDigue_1920x1200.jpg" alt="bing.com-哇岛东部的婆罗摩火山，印度尼西亚" title="bing.com-哇岛东部的婆罗摩火山，印度尼西亚"></p>
<p>Javascript中几种数据类型简述。</p>
<span id="more"></span>

<p>Javascript脚本语言同其他语言一样，有它自身的基本数据类型，表达式和算术运算符及程序的基本程序框架。</p>
<p>Javascript中大致分为9种数据类型，分别为：</p>
<ul>
<li><p>值类型（原始数据类型、基本数据类型）：<strong>字符串（String）</strong>、<strong>数字（Number）</strong>、<strong>布尔（Boolean）</strong>、<strong>Null</strong>、<strong>Undefined</strong>、<strong>Symbol</strong></p>
</li>
<li><p>引用类型：<strong>对象（Object）</strong>、<strong>数组（Array）</strong>、<strong>函数（Function）</strong></p>
</li>
</ul>
<blockquote>
<p>注：Symbol是ES6引入的一种新的原始数据类型，标识独一无二的值。</p>
</blockquote>
<p>JavaScript 拥有<strong>动态类型</strong>。这意味着相同的变量可用作不同的类型。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">var a</span><br><span class="line">console.log(a)  //undefined</span><br><span class="line">a = 123</span><br><span class="line">console.log(a)  //123</span><br><span class="line">a = &#x27;abc&#x27;</span><br><span class="line">console.log(a)  //abc</span><br><span class="line">a = [1,2,3]</span><br><span class="line">console.log(a)  //[1,2,3]</span><br></pre></td></tr></table></figure>

<h3 id="1-值类型（原始数据类型、基本数据类型）"><a href="#1-值类型（原始数据类型、基本数据类型）" class="headerlink" title="1.值类型（原始数据类型、基本数据类型）"></a>1.值类型（原始数据类型、基本数据类型）</h3><ul>
<li><p>字符串（String）：String类型表示文本数据并编码为<code>UTF-16</code>代码单位的16位无符号整数值序列。字符串中的每个元素在字符串中占据一个位置。第一个元素的索引为 0，下一个是索引 1，依此类推。字符串的长度是它的元素的数量。</p>
</li>
<li><p>数字（Number）：Number 类型是一种基于<strong>IEEE 754标准的双精度64位二进制格式</strong>的值。它能够存储2^-1074（Number.MIN_VALUE）和2^1024（Number.MAX_VALUE）之间的正浮点数，以及-2^-1074 和 -2^1024 之间的负浮点数，但是它仅能安全地存储在 -(2^53 − 1)（Number.MIN_SAFE_INTEGER）到 2^53 − 1（Number.MAX_SAFE_INTEGER）范围内的整数。超出这个范围，JavaScript 将不能安全地表示整数；相反，它们将由双精度浮点近似表示。你可以使用 Number.isSafeInteger() 检查一个数是否在安全的整数范围内。</p>
</li>
</ul>
<p>极大或极小的数字可以通过科学（指数）计数法来书写</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">var y=123e5;      // 12300000</span><br><span class="line">var z=123e-5;     // 0.00123</span><br></pre></td></tr></table></figure>

<ul>
<li><p>Boolean：表示一个逻辑实体并且包括两个值：true 和 false。布尔值通常用于条件运算。</p>
</li>
<li><p>Null：Null类型是第二个<strong>只有一个值</strong>的数据类型。其特殊<strong>值就是Null</strong>。从逻辑角度上看，null是一个<strong>空的对象指针</strong>。而这也正是使用typeof操作符检测null值，会返回“object”的原因。</p>
</li>
<li><p>Undefined：Undefined类型<strong>只有一个值</strong>，即特殊<strong>值是undefined</strong>。表示<strong>变量不含有值</strong>。在声明变量，但未对其加以初始化时，这个变量值就是undefined。</p>
</li>
<li><p>Symbol：符号 (Symbols) 是 ECMAScript 第 6 版新定义的。符号类型是唯一的并且是不可修改的。</p>
</li>
</ul>
<hr>
<h3 id="2-引用数据类型"><a href="#2-引用数据类型" class="headerlink" title="2.引用数据类型"></a>2.引用数据类型</h3><ul>
<li><p>Object：又称为<strong>对象</strong>，是一组<strong>数据和功能（函数）的集合</strong>。可以用new操作符后跟要创建的对象类型的名称来创建。也可以用字面量表示法创建。在其中添加不同名（包含空字符串在内的任意字符串）的属性。对象属性有两种寻址方式：<strong>name&#x3D;person.lastname;</strong><br><strong>name&#x3D;person[“lastname”];</strong></p>
</li>
<li><p>Array：数组用方括号书写。数组的项目由逗号分隔。数组<strong>索引基于零</strong>，这意味着第一个项目是 [0]，第二个项目是 [1]，以此类推。<strong>数组的每一项可以保存任何类型的数据</strong>。<br>var cars&#x3D;new Array();<br>cars[0]&#x3D;”Saab”;<br>cars[1]&#x3D;”Volvo”;<br>cars[2]&#x3D;”BMW”;<br>或者<br>var cars&#x3D;new Array(“Saab”,”Volvo”,”BMW”);<br>或者<br>var cars&#x3D;[“Saab”,”Volvo”,”BMW”];</p>
</li>
<li><p>Function：ECMAScript中的函数是对象，与其他引用类型一样具有属性和方法。因此，函数名实际是一个指向函数对象的指针。</p>
</li>
</ul>
<hr>
<h3 id="3-值类型与引用类型"><a href="#3-值类型与引用类型" class="headerlink" title="3.值类型与引用类型"></a>3.值类型与引用类型</h3><h4 id="1-特性"><a href="#1-特性" class="headerlink" title="(1).特性"></a>(1).特性</h4><ul>
<li><p>值类型：</p>
<ul>
<li>保存在<strong>栈内存</strong>中的简单数据段</li>
<li>数据是不可变的，即不能强行修改 Array.prototype.sort.call(‘abc’);(会报错)</li>
<li>没有原型链中的 <em>proto</em> 属性</li>
</ul>
</li>
<li><p>引用类型：</p>
<ul>
<li>引用类型正在创建时会<strong>分配两个空间</strong><ul>
<li>一块在<strong>堆</strong>上，储存引用类型本身的数据（当然数据量会比较大）</li>
<li>一块在<strong>栈</strong>上，储存对堆上数据的引用（存储堆上的内存地址，也就是指针）</li>
</ul>
</li>
<li><strong>引用类型是可变的</strong>：即 let a&#x3D;{}; a.x&#x3D;1;</li>
<li>function <strong>参数是值传递</strong>，不能修改引用</li>
</ul>
</li>
</ul>
<h4 id="2-检测类型"><a href="#2-检测类型" class="headerlink" title="(2).检测类型"></a>(2).检测类型</h4><h5 id="①-typeof"><a href="#①-typeof" class="headerlink" title="①.typeof"></a>①.typeof</h5><table>
<thead>
<tr>
<th>类型</th>
<th>结果</th>
</tr>
</thead>
<tbody><tr>
<td>String</td>
<td>string</td>
</tr>
<tr>
<td>Number</td>
<td>number</td>
</tr>
<tr>
<td>Boolean</td>
<td>boolean</td>
</tr>
<tr>
<td>Undefined</td>
<td>undefined</td>
</tr>
<tr>
<td>Object\Array\RegExp\null\Date\Error</td>
<td>object</td>
</tr>
<tr>
<td>Function</td>
<td>function</td>
</tr>
<tr>
<td>Symbol</td>
<td>symbol</td>
</tr>
</tbody></table>
<ul>
<li>值类型：<ul>
<li>使用<strong>typeof 可以检测基本数据类型</strong></li>
<li>但是 typeof(null) &#x3D;&#x3D; ‘object’<ul>
<li>null 得到检测错误是历史遗留问题，在 JS 的最初版本中使用的是 32 位系统，为了性能考虑使用低位存储变量的类型信息，000 开头代表是对象然而 null 表示为全零，所以将它错误的判断为 object 。</li>
</ul>
</li>
</ul>
</li>
</ul>
<h5 id="②-instanceof"><a href="#②-instanceof" class="headerlink" title="②.instanceof"></a>②.instanceof</h5><p><strong>instanceof</strong>运算符需要<strong>指定一个构造函数</strong>，或者说<strong>指定一个特定的类型</strong>，它用来判断这个构造函数的原型是否在给定对象的原型链上。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">123 instanceof Number                                   //false</span><br><span class="line">&#x27;dsfsf&#x27; instanceof String                               //false</span><br><span class="line">false instanceof Boolean                                //false</span><br><span class="line">[1,2,3] instanceof Array                                //true</span><br><span class="line">&#123;a:1,b:2,c:3&#125; instanceof Object                         //true</span><br><span class="line">function()&#123;console.log(&#x27;aaa&#x27;);&#125; instanceof Function     //true</span><br><span class="line">undefined instanceof Object                             //false</span><br><span class="line">null instanceof Object                                  //false</span><br><span class="line">new Date() instanceof Date                              //true</span><br><span class="line">/^[a-zA-Z]&#123;5,20&#125;$/ instanceof RegExp                    //true</span><br><span class="line">new Error() instanceof Error                            //true</span><br></pre></td></tr></table></figure>

<blockquote>
<p>注：null和undefined都返回了false，这是因为它们的类型就是自己本身，并不是Object创建出来它们，所以返回了false</p>
</blockquote>
<blockquote>
<p>注：上面示例中没有检测出Number、String、Boolean的类型，采用如下声明方法即可。</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">var num = new Number(123);</span><br><span class="line">num instanceof Number                                   //true</span><br><span class="line">var str = new String(&#x27;dsfsf&#x27;);</span><br><span class="line">str instanceof String                                   //true</span><br><span class="line">var boolean = new Boolean(false);</span><br><span class="line">boolean instanceof Boolean                              //true</span><br></pre></td></tr></table></figure>

<h5 id="③-constructor"><a href="#③-constructor" class="headerlink" title="③.constructor"></a>③.constructor</h5><ul>
<li>constructor是prototype对象上的属性，<strong>指向构造函数</strong>。</li>
<li>根据实例对象寻找属性的顺序，若实例对象上没有实例属性或方法时，就去<strong>原型链上寻找</strong>。因此，实例对象也是能使用 constructor 属性的。</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">var num  = 123;</span><br><span class="line">var str  = &#x27;abcdef&#x27;;</span><br><span class="line">var bool = true;</span><br><span class="line">var arr  = [1, 2, 3, 4];</span><br><span class="line">var json = &#123;name:&#x27;wenzi&#x27;, age:25&#125;;</span><br><span class="line">var func = function()&#123; console.log(&#x27;this is function&#x27;); &#125;</span><br><span class="line">var und  = undefined;</span><br><span class="line">var nul  = null;</span><br><span class="line">var date = new Date();</span><br><span class="line">var reg  = /^[a-zA-Z]&#123;5,20&#125;$/;</span><br><span class="line">var error= new Error();</span><br><span class="line"></span><br><span class="line">console.log(</span><br><span class="line">    num.constructor==Number,                            //true</span><br><span class="line">    str.constructor==String,                            //true</span><br><span class="line">    bool.constructor==Boolean,                          //true</span><br><span class="line">    arr.constructor==Array,                             //true</span><br><span class="line">    json.constructor==Object,                           //true</span><br><span class="line">    func.constructor==Function,                         //true</span><br><span class="line">    date.constructor==Date,                             //true</span><br><span class="line">    reg.constructor==RegExp,                            //true</span><br><span class="line">    error.constructor==Error,                           //true</span><br><span class="line">);</span><br></pre></td></tr></table></figure>

<blockquote>
<p>注：<strong>undefined和null没有constructor属性</strong></p>
</blockquote>
<h5 id="④-toString"><a href="#④-toString" class="headerlink" title="④.toString()"></a>④.toString()</h5><ul>
<li>可以通过toString()来获取每个对象的类型。</li>
<li>为了每个对象都能通过<code>Object.prototype.toString()</code>来检测，需要以<code>Function.prototype.call()</code>或者 <code>Function.prototype.apply()</code>的形式来调用</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">Object.prototype.toString.call(123);                                             //&quot;[object Number]&quot;</span><br><span class="line">Object.prototype.toString.call(&#x27;abcdef&#x27;);                                        //&quot;[object String]&quot;</span><br><span class="line">Object.prototype.toString.call(true);                                            //&quot;[object Boolean]&quot;</span><br><span class="line">Object.prototype.toString.call([1, 2, 3, 4]);                                    //&quot;[object Array]&quot;</span><br><span class="line">Object.prototype.toString.call(&#123;name:&#x27;wenzi&#x27;, age:25&#125;);                          //&quot;[object Object]&quot;</span><br><span class="line">Object.prototype.toString.call(function()&#123; console.log(&#x27;this is function&#x27;); &#125;);  //&quot;[object Function]&quot;</span><br><span class="line">Object.prototype.toString.call(undefined);                                       //&quot;[object Undefined]&quot;</span><br><span class="line">Object.prototype.toString.call(null);                                            //&quot;[object Null]&quot;</span><br><span class="line">Object.prototype.toString.call(new Date());                                      //&quot;[object Date]&quot;</span><br><span class="line">Object.prototype.toString.call(/^[a-zA-Z]&#123;5,20&#125;$/);                              //&quot;[object RegExp]&quot;</span><br><span class="line">Object.prototype.toString.call(new Error());                                     //&quot;[object Error]&quot;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>扩展：封装一个准确获取变量类型的函数</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">function getDataType(obj) &#123;</span><br><span class="line">  let type = typeof obj;</span><br><span class="line"></span><br><span class="line">  if (type !== &#x27;object&#x27;) &#123;</span><br><span class="line">    return type;</span><br><span class="line">  &#125;</span><br><span class="line">  //如果不是object类型的数据，直接用typeof就能判断出来</span><br><span class="line"></span><br><span class="line">  //如果是object类型数据，准确判断类型必须使用Object.prototype.toString.call(obj)的方式才能判断</span><br><span class="line">  return Object.prototype.toString.call(obj).replace(/^\[object (\S+)\]$/, &#x27;$1&#x27;);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<hr>
<h3 id="4-真值与假值"><a href="#4-真值与假值" class="headerlink" title="4.真值与假值"></a>4.真值与假值</h3><p>JS 中除了 ‘假’ 值就是 ‘真’ 值，’假’ 值共有七个：</p>
<ul>
<li>undefined</li>
<li>null</li>
<li>false</li>
<li>NaN</li>
<li>‘’</li>
<li>0</li>
<li>-0</li>
</ul>
<p>在条件判断的隐式转换中：”假” 值会转换为 false，”真” 值会转换为 true;</p>
<hr>
<p><em><strong>本文参考文献：</strong></em></p>
<p><em><strong><a class="link"   target="_blank" rel="noopener" href="https://www.php.cn/js-tutorial-473143.html#:~:text=JavaScript%E8%AF%AD%E8%A8%80%E7%9A%84%E6%AF%8F%E4%B8%80%E4%B8%AA%E5%80%BC%EF%BC%8C%E9%83%BD%E5%B1%9E%E4%BA%8E%E6%9F%90%E4%B8%80%E7%A7%8D%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%E3%80%82%20JavaScript%E7%9A%84%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%EF%BC%8C%E5%85%B1%E6%9C%899%E7%A7%8D%EF%BC%9A%20%E5%80%BC%E7%B1%BB%E5%9E%8B%20%28%E5%9F%BA%E6%9C%AC%E7%B1%BB%E5%9E%8B%29%EF%BC%9A%E5%AD%97%E7%AC%A6%E4%B8%B2%EF%BC%88String%EF%BC%89%E3%80%81%E6%95%B0%E5%AD%97%20%28Number%29%E3%80%81%E5%B8%83%E5%B0%94,%28Boolean%29%E3%80%81%E7%A9%BA%EF%BC%88Null%EF%BC%89%E3%80%81%E6%9C%AA%E5%AE%9A%E4%B9%89%EF%BC%88Undefined%EF%BC%89%E3%80%81Symbol%E3%80%82%20%E5%BC%95%E7%94%A8%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%EF%BC%9A%E5%AF%B9%E8%B1%A1%20%28Object%29%E3%80%81%E6%95%B0%E7%BB%84%20%28Array%29%E3%80%81%E5%87%BD%E6%95%B0%20%28Function%29%E3%80%82" >PHP中文网 ： javascript有哪几种数据类型<i class="fas fa-external-link-alt"></i></a></strong></em></p>
<p><em><strong><a class="link"   target="_blank" rel="noopener" href="https://blog.csdn.net/cherry_vicent/article/details/112388983" >CSDN ： javascript有哪些数据类型？<i class="fas fa-external-link-alt"></i></a></strong></em></p>
<p><em><strong><a class="link"   target="_blank" rel="noopener" href="https://juejin.cn/post/6992754058297622542#heading-7" >稀土掘金 : Javascript 的数据类型详解<i class="fas fa-external-link-alt"></i></a></strong></em></p>

            </div>

            

            
                <ul class="post-tags-box">
                    
                        <li class="tag-item">
                            <a href="/tags/Javascript%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B/">#Javascript数据类型</a>&nbsp;
                        </li>
                    
                </ul>
            

            
                <div class="article-nav">
                    
                        <div class="article-prev">
                            <a class="prev"
                               rel="prev"
                               href="/2023/06/05/Javascript%E4%B9%8B%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0/"
                            >
                            <span class="left arrow-icon flex-center">
                              <i class="fas fa-chevron-left"></i>
                            </span>
                                <span class="title flex-center">
                                <span class="post-nav-title-item">Javascript之构造函数</span>
                                <span class="post-nav-item">Prev posts</span>
                            </span>
                            </a>
                        </div>
                    
                    
                        <div class="article-next">
                            <a class="next"
                               rel="next"
                               href="/2023/06/05/javascript%E4%B9%8B%E5%BA%8F%E5%88%97%E5%8C%96%E4%B8%8E%E5%8F%8D%E5%BA%8F%E5%88%97%E5%8C%96/"
                            >
                            <span class="title flex-center">
                                <span class="post-nav-title-item">Javascript之序列化与反序列化</span>
                                <span class="post-nav-item">Next posts</span>
                            </span>
                                <span class="right arrow-icon flex-center">
                              <i class="fas fa-chevron-right"></i>
                            </span>
                            </a>
                        </div>
                    
                </div>
            

            
        </div>

        
    </div>
</div>


                
            </div>

        </div>

        <div class="page-main-content-bottom">
            
<footer class="footer">
    <div class="info-container">
        <div class="copyright-info info-item">
            &copy;
            
                <span>2020</span> -
            
            2024
            
                &nbsp;<i class="fas fa-heart icon-animate"></i>
                &nbsp;<a href="/">aaton</a>
            
        </div>
        
            <script async 
                    src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
            <div class="website-count info-item">
                
                    Visitor Count&nbsp;<span id="busuanzi_value_site_uv"></span>&ensp;
                
                
                    Totalview&nbsp;<span id="busuanzi_value_site_pv"></span>
                
            </div>
        
        <div class="theme-info info-item">
            Powered by <a target="_blank" href="https://hexo.io">Hexo</a>&nbsp;|&nbsp;Theme&nbsp;<a class="theme-version" target="_blank" href="https://github.com/XPoet/hexo-theme-keep">Keep v3.6.1</a>
        </div>
        
        
    </div>
</footer>

        </div>
    </div>

    
        <div class="post-tools">
            <div class="post-tools-container">
    <ul class="tools-list">
        <!-- TOC aside toggle -->
        

        <!-- go comment -->
        
    </ul>
</div>

        </div>
    

    <div class="right-bottom-side-tools">
        <div class="side-tools-container">
    <ul class="side-tools-list">
        <li class="tools-item tool-font-adjust-plus flex-center">
            <i class="fas fa-search-plus"></i>
        </li>

        <li class="tools-item tool-font-adjust-minus flex-center">
            <i class="fas fa-search-minus"></i>
        </li>

        <li class="tools-item tool-dark-light-toggle flex-center">
            <i class="fas fa-moon"></i>
        </li>

        <!-- rss -->
        

        
            <li class="tools-item tool-scroll-to-top flex-center">
                <i class="fas fa-arrow-up"></i>
            </li>
        

        <li class="tools-item tool-scroll-to-bottom flex-center">
            <i class="fas fa-arrow-down"></i>
        </li>
    </ul>

    <ul class="exposed-tools-list">
        <li class="tools-item tool-toggle-show flex-center">
            <i class="fas fa-cog fa-spin"></i>
        </li>
        
    </ul>
</div>

    </div>

    <div class="zoom-in-image-mask">
    <img class="zoom-in-image">
</div>


    

</main>




<script src="/js/utils.js"></script>

<script src="/js/main.js"></script>

<script src="/js/header-shrink.js"></script>

<script src="/js/back2top.js"></script>

<script src="/js/dark-light-toggle.js"></script>







    
<script src="/js/code-block.js"></script>





<div class="post-scripts">
    
        
<script src="/js/post-helper.js"></script>

        
        
    
</div>



</body>
</html>
